﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NF.Core
{
    public struct NPoint
    {
        public NPoint(int order)
        {
            V = new double[order];
        }

        public NPoint(int order, double initialValue)
        {
            V = new double[order];
            for (int i = 0; i < order; ++i)
                V[i] = initialValue;
        }

        public NPoint(params double[] v)
        {
            V = v;
        }

        public static double Distance(NPoint a, NPoint b)
        {
            if (a.Order != b.Order)
                throw new ArgumentException();

            double d = 0.0, x;

            for (int i = 0; i < a.Order; ++i)
            {
                x = a[i] - b[i];
                d += (x * x);
            }

            return Math.Sqrt(d);
        }

        public double[] V;

        public double this[int index]
        {
            get { return V[index]; }
            set { V[index] = value; }
        }

        public int Order
        {
            get { return V.Length; }
        }
    }
}
